/*
 * @Author: shanghongyun 2879455630@qq.com
 * @Date: 2025-05-30 16:43:22
 * @LastEditors: shanghongyun 2879455630@qq.com
 * @LastEditTime: 2025-06-16 18:57:25
 * @FilePath: \A05\Drive\key.c
 * @Description: 按键管理
 */
#include "key.h"




/**
 * @description: 按键检测
 * @param {key_t} *pkey
 * @return {*}
 */
void Key_detect(key_t *pkey){
    /*按键按下*/
    if(pkey->get_key_value()){
        pkey->press_time++;
        if(pkey->press_time >= pkey->short_press_time && pkey->long_lock == 0){
            pkey->short_wait = 1;
        }
        if(pkey->press_time > pkey->long_press_time_min && pkey->long_lock == 0){
            pkey->short_wait = 0;
            pkey->long_flag = 1;
            pkey->press_time = 0;
            pkey->long_lock = 1;
            // pkey->long_effect = 1;
            // if(pkey->press_time > pkey->long_press_time_max){
            //     pkey->long_effect = 0;
            // }
        }
    } 
    else{
        pkey->press_time = 0;
        pkey->long_lock = 0;
        if(pkey->short_wait){
            pkey->short_wait = 0;
            pkey->short_flag = 1;
        }
        // else{
        //     if(pkey->long_effect == 1){
        //         pkey->long_effect = 0;
        //         pkey->long_flag = 1;
        //     }
        // }
    }
}


uint8_t get_key_L(void) {
    if(Get_KeyL() == 0){
        return 1;
    } else {
        return 0;
    }
}

uint8_t get_key_R(void){
    if(Get_KeyR() == 0){
        return 1;
    } else {
        return 0;
    }
}

